package com.game.majiang.vo;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.sql.rowset.CachedRowSet;

import com.game.majiang.algorithm.doudizhu.Card;
import com.game.majiang.algorithm.doudizhu.DoudizhuAIRandomcards;
import com.game.majiang.algorithm.doudizhu.DoudizhuAIRandomcardsAll;
import com.game.majiang.algorithm.doudizhu.DoudizhuAIRandomcardsServer;
import com.game.server.db.Parameter;
import com.game.server.db.SqlHelper;

public class DoudizhuAIVo {
    /** 牌组         3,3,3;4,4,4;5,5,5;7,8,9,10,j;2;x,d;*/
    //private String cards;
    
    /**
     *地主的牌 和获得地主放入牌组的位置 0,7;1,10;2,a;
     */
    //private String dizhucards;
    

    public static DoudizhuAIRandomcardsServer getDouDiZhuAIVo()
    {
    	String cmdText = "select g.cards, g.dizhucards,g.huapai from doudizhuai g";
    	CachedRowSet rs = SqlHelper.getResultSet(cmdText, new Parameter[0]);
    	DoudizhuAIRandomcardsServer dzaicardsserver = new DoudizhuAIRandomcardsServer();
    	dzaicardsserver.cardsserver = new ArrayList<DoudizhuAIRandomcardsAll>();
    	dzaicardsserver.cardsserverhuapai = new ArrayList<DoudizhuAIRandomcardsAll>();
    	try {
    		  while (rs.next())
	          {
    			  DoudizhuAIRandomcardsAll dzaicardsall = new DoudizhuAIRandomcardsAll();
				  dzaicardsall.cardsall = new ArrayList<DoudizhuAIRandomcards>();
				  dzaicardsall.cardsdizhu = new ArrayList<DoudizhuAIRandomcards>();
				  dzaicardsall.huapai = rs.getInt(3);
    			  String cards = rs.getString(1);
    			  String dizhucards = rs.getString(2);
    			  
    			  ArrayList<Card> acards = new ArrayList<Card>();
    			  
    			  String cards2[] = cards.split(";");
    			  for(int i=0; i<cards2.length; i++)
    			  {
    				  String cards3[] = cards2[i].split(",");
					  DoudizhuAIRandomcards temp = new DoudizhuAIRandomcards();
					  temp.cards = new ArrayList<Card>();
    				  for(int j=0; j<cards3.length; j++)
    				  {
    					  Card temp2 = new Card(cards3[j], acards);
    					  temp.cards.add(temp2);
    					  acards.add(temp2);
    				  }
    				  dzaicardsall.cardsall.add(temp);
    			  }
    			  
    			  String cards4[] = dizhucards.split(";");
    			  for(int i=0; i<cards4.length; i++)
    			  {
    				  String cards5[] = cards4[i].split(",");
					  DoudizhuAIRandomcards temp = new DoudizhuAIRandomcards();
					  temp.cards = new ArrayList<Card>();

					  Card temp2 = new Card(cards5[1], acards);
					  temp.cards.add(temp2);
					  temp.index = Integer.parseInt(cards5[0]);
					  acards.add(temp2);
    				  
    				  dzaicardsall.cardsdizhu.add(temp);
    			  }
    			  if (dzaicardsall.huapai == 0) {
    				  dzaicardsserver.cardsserver.add(dzaicardsall);
				} else {
					dzaicardsserver.cardsserverhuapai.add(dzaicardsall);
				}
    			  
	         }
		 } catch (SQLException e) {
			// TODO Auto-generated catch block
			 e.printStackTrace();
		 }
 
    	return dzaicardsserver;
    }
}
